﻿@using Microsoft.AspNetCore.Http.Features

@{
    var shouldShowBanner = ViewBag.PageName == "register" || ViewBag.PageName == "login";
    var consentFeature = Context.Features.Get<ITrackingConsentFeature>();
    var showBanner = shouldShowBanner && !consentFeature?.CanTrack ?? false;
    var cookieString = consentFeature?.CreateConsentCookie();
}

@if (showBanner)
{
    <div id="cookieConsent" class="alert bg-fusion-500 alert-dismissible fade show position-fixed pos-top pos-left pos-right rounded-0 border-0 m-0 shadow-lg" role="alert" style="z-index: 999999;margin: 0 !important;">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true"><i class="fal fa-times"></i></span>
        </button>
        <h4 class="m-0">This website is using cookies.</h4>
        <p>
            We use them to give you the best experience. If you continue using our website, we'll assume that you are happy to receive all cookies on this website.
        </p>
        <div class="d-flex mt-3">
            <button class="btn btn-sm btn-warning mr-2" data-dismiss="alert" aria-label="Close" data-cookie-string="@cookieString">Accept</button>
            <button class="btn btn-sm btn-light">Learn more</button>
        </div>
    </div>
    <script>
        (function () {
            var button = document.querySelector("#cookieConsent button[data-cookie-string]");
            button.addEventListener("click", function () {
                document.cookie = button.dataset.cookieString;
            }, false);
        })();
    </script>
}